<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function template import_symbol</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_dll/reference.html#doxygen.shared_library_refcountable_reference.import_8hpp" title="Header &lt;boost/dll/import.hpp&gt;">
<link rel="prev" href="../shared_library_reference/smart__library_8hpp_1a8e9c15aa4edf4bd334aed77f1f4c40b7.html" title="Function template get">
<link rel="next" href="import_8hpp_1a7ea7e10c20f83517dcc0acb6a64efa11.html" title="Function template import_alias">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../shared_library_reference/smart__library_8hpp_1a8e9c15aa4edf4bd334aed77f1f4c40b7.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_dll/reference.html#doxygen.shared_library_refcountable_reference.import_8hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="import_8hpp_1a7ea7e10c20f83517dcc0acb6a64efa11.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="doxygen.shared_library_refcountable_reference.import_8hpp_1aef427f71fecdb92981fe5a509a917801"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Function template import_symbol</span></h2>
<p>boost::dll::import_symbol</p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../boost_dll/reference.html#doxygen.shared_library_refcountable_reference.import_8hpp" title="Header &lt;boost/dll/import.hpp&gt;">boost/dll/import.hpp</a>&gt;

</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> 
  <span class="identifier">result_type</span> <span class="identifier">import_symbol</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">dll</span><span class="special">::</span><span class="identifier">fs</span><span class="special">::</span><span class="identifier">path</span> <span class="special">&amp;</span> lib<span class="special">,</span> 
                            <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span> name<span class="special">,</span> 
                            <span class="identifier">load_mode</span><span class="special">::</span><span class="identifier">type</span> mode <span class="special">=</span> <span class="identifier">load_mode</span><span class="special">::</span><span class="identifier">default_mode</span><span class="special">)</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.12.8.3.2.4.4"></a><h2>Description</h2>
<p>Returns callable object or std::shared_ptr&lt;T&gt; (boost::shared_ptr&lt;T&gt; if BOOST_DLL_USE_BOOST_SHARED_PTR is defined) that holds the symbol imported from the loaded library. Returned value refcounts usage of the loaded shared library, so that it won't get unload until all copies of return value are not destroyed.</p>
<p>This call will succeed if call to  <a class="link" href="../../">boost::dll::shared_library</a><code class="computeroutput">::has(const char* )</code> function with the same symbol name returned <code class="computeroutput">true</code>.</p>
<p>For importing symbols by <span class="bold"><strong>alias</strong></span> names use  <a class="link" href="../../">boost::dll::import_alias</a> method.</p>
<p><span class="bold"><strong>Examples:</strong></span> </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="special">&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">import_symbol</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="special">&gt;</span><span class="special">(</span><span class="string">"test_lib.so"</span><span class="special">,</span> <span class="string">"integer_func_name"</span><span class="special">)</span><span class="special">;</span>

<span class="keyword">auto</span> <span class="identifier">f_cpp11</span> <span class="special">=</span> <span class="identifier">import_symbol</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span><span class="special">&gt;</span><span class="special">(</span><span class="string">"test_lib.so"</span><span class="special">,</span> <span class="string">"integer_func_name"</span><span class="special">)</span><span class="special">;</span>
</pre>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">import_symbol</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span><span class="special">(</span><span class="string">"test_lib.so"</span><span class="special">,</span> <span class="string">"integer_name"</span><span class="special">)</span><span class="special">;</span>
</pre>
<p><span class="bold"><strong>Template</strong></span> <span class="bold"><strong>parameter</strong></span> <span class="bold"><strong>T:</strong></span> Type of the symbol that we are going to import. Must be explicitly specified.</p>
<p>


xmlonly &lt;link linkend='boost.dll.fs.system_error'&gt;boost::dll::fs::system_error&lt;/link&gt; if symbol does not exist or if the DLL/DSO was not loaded. Overload that accepts path also throws std::bad_alloc in case of insufficient memory. </p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">lib</code></span></p></td>
<td><p>Path to shared library or shared library to load function from. </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">name</code></span></p></td>
<td><p>Null-terminated C or C++ mangled name of the function to import. Can handle std::string, char*, const char*. </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">mode</code></span></p></td>
<td><p>An mode that will be used on library load.</p></td>
</tr>
</tbody>
</table></div></td>
</tr>
<tr>
<td><p><span class="term">Returns:</span></p></td>
<td><p>callable object if T is a function type, or std::shared_ptr&lt;T&gt; (boost::shared_ptr&lt;T&gt; if BOOST_DLL_USE_BOOST_SHARED_PTR is defined) if T is an object type.</p></td>
</tr>
<tr>
<td><p><span class="term">Throws:</span></p></td>
<td> </td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="copyright-footer">Copyright © 2014 Renato Tegon Forti, Antony Polukhin<br>Copyright © 2015 Antony Polukhin<br>Copyright © 2016 Antony Polukhin, Klemens Morgenstern<br>Copyright © 2017-2025 Antony
      Polukhin<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../shared_library_reference/smart__library_8hpp_1a8e9c15aa4edf4bd334aed77f1f4c40b7.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_dll/reference.html#doxygen.shared_library_refcountable_reference.import_8hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="import_8hpp_1a7ea7e10c20f83517dcc0acb6a64efa11.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
